Page({
  data: {
    courseId: null,
    kejianlist: null//课件的list

  },



  onLoad: function (options) {
    console.log(options)
    var that = this

    var _courseId = options.course
    that.setData({
      courseId: _courseId
    })

    getkejianlist(that);

  },
  onShow: function () {
  },

  onPullDownRefresh: function () {

  },

  onReachBottom: function () {

  },


  downloadFile(event) {
    var that = this;
    console.log(event);
    wx.showLoading({
      title: '下载中...',
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 5000)

    wx.showLoading({
      title: '正在打开...',
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 5000)
    var uri = event.currentTarget.dataset.uri
    var url = "https://geek-team.xin/file/downloadFile?uri=" + uri + "";
    wx.downloadFile({
      url: url,
      success: function (res) {
        console.log(res);
        var filepath = res.tempFilePath;
        console.log(filepath);
        wx.openDocument({
          filePath: res.tempFilePath,
          success: function (res) {
            console.log("打开文档成功");
          },
          fail: function (res) {
            console.log(res)
            wx.showToast({
              title: '不支持的文件类型',
              image: '/images/error.png',
            })
          }, complete: function (res) {
            console.log(res)
          }
        })
      },
      fail: function () {
        console.log("失败");
      }
    })
  }
})
//发送课程ID 得到一个课件列表：需要课件的课件名称 发布时间 文件大小

function getkejianlist(that) {
  // console.log(that)
  wx.request({
    url: `https://geek-team.xin/ppt/findByCourse`,
    method: 'POST',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    data: {
      course: that.data.courseId
    },
    success(res) {
      if (res.data != []) {
        that.setData({
          kejianlist: res.data
        })
        console.log(res.data)
      }
    },
    fail: (e) => console.log(e)
  })
};






